package com.sfeir.gwt.webding.client.showcase;

import java.util.List;
import java.util.Map.Entry;

import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.sfeir.gwt.webding.client.component.Info;
import com.sfeir.gwt.webding.client.component.label.LabelListBox;
import com.sfeir.gwt.webding.client.component.label.LabelListBoxString;
import com.sfeir.gwt.webding.client.component.label.LabelMultiListBox;
import com.sfeir.gwt.webding.client.showcase.ShowcaseAnnotations.ShowcaseSource;


public class TabListBox extends LazyTab {
    /**
     * 
     */
    @ShowcaseSource
    protected Widget createTab() {
        VerticalPanel panel = new VerticalPanel();

        LabelListBox<Boolean> field1 = new LabelListBox<Boolean>("Listbox");
        field1.addItem("Oui", true);
        field1.addItem("Non", false);
        field1.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
            public void onValueChange(ValueChangeEvent<Boolean> event) {
                Info.display("Nouvelle valeur : " + event.getValue());
            }
        });
        panel.add(field1);

        LabelMultiListBox<Integer> field2 = new LabelMultiListBox<Integer>("MultiListbox");
        field2.setMandatory(true);
        field2.setVisibleItemCount(2);
        field2.setComponentWidth("200px");
        field2.addItem("Valeur 1", 1);
        field2.addItem("Valeur 2", 2);
        field2.addItem("Valeur 3", 3);
        field2.addValueChangeHandler(new ValueChangeHandler<List<Integer>>() {
            public void onValueChange(ValueChangeEvent<List<Integer>> event) {
                Info.display("Nouvelle valeur : " + event.getValue().toString());
            }
        });
        panel.add(field2);

        LabelListBox<String> field3 = new LabelListBox<String>("Affichage de la valeur");
        field3.setDisplayValue(true);
        for (Entry<String, String> entry : listDepartement.entrySet()) {
            field3.addItem(entry.getValue(), entry.getKey());
        }
        field3.addValueChangeHandler(new ValueChangeHandler<String>() {
            public void onValueChange(ValueChangeEvent<String> event) {
                Info.display("Nouvelle valeur : " + event.getValue());
            }
        });
        panel.add(field3);

        LabelListBox<String> field4 = new LabelListBox<String>("Remplissage par une liste");
        field4.addItems(listDepartement.keySet());
        field4.addValueChangeHandler(new ValueChangeHandler<String>() {
            public void onValueChange(ValueChangeEvent<String> event) {
                Info.display("Nouvelle valeur : " + event.getValue());
            }
        });
        panel.add(field4);

        LabelListBox<String> field5 = new LabelListBox<String>("Remplissage par une map");
        field5.addItems(listDepartement);
        field5.addValueChangeHandler(new ValueChangeHandler<String>() {
            public void onValueChange(ValueChangeEvent<String> event) {
                Info.display("Nouvelle valeur : " + event.getValue());
            }
        });
        panel.add(field5);

        LabelListBox<String> field6 = new LabelListBox<String>("Valeur par défaut");
        field6.setMandatory(true);
        field6.addDefaultItem();
        field6.addItems(listDepartement);
        panel.add(field6);

        LabelListBoxString field7 = new LabelListBoxString("Valeur par défaut Personnalisé");
        field7.setMandatory(true);
        field7.addDefaultItem("Peut-être");
        field7.addItem("oui");
        field7.addItem("non");
        field7.addValueChangeHandler(new ValueChangeHandler<String>() {
            public void onValueChange(ValueChangeEvent<String> event) {
                Info.display("Nouvelle valeur : " + event.getValue());
            }
        });
        field7.setMandatoryErrorText("Il faudrait se décider...");
        panel.add(field7);

        return panel;
    }

    @Override
    public String getDescription() {
        return "Champs de selection déroulante";
    }

    @Override
    public String getName() {
        return "Champs ListBox";
    }
}